#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
import socket

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(levelname)s %(threadName)s %(message)s')
LOG = logging.getLogger('client')


def request():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    LOG.debug('connecting...')
    sock.connect(('localhost', 8000))
    LOG.debug('connected.')
    LOG.debug('sending a request...')
    sock.send('GET / HTTP/1.1')
    LOG.debug('sended.')
    while True:
        LOG.debug('waiting a responce...')
        data = sock.recv(1024)
        LOG.debug('got a responce.')
        if not data:
            break
        LOG.debug('recv: %r', data)


def main():
    from multiprocessing.pool import ThreadPool
    pool = ThreadPool(5)
    for _ in range(5):
        pool.apply_async(request)
    pool.close()
    pool.join()


if __name__ == '__main__':
    main()
